// 节流
export function throttle(fn, delay = 1000) {
    let begin = 0;
    return function() {
        let now = new Date().getTime();
        if (now - begin >= delay) {
            fn.apply(this, arguments);
            begin = now;
        }
    }
}

// 防抖
export function debounce(fn, delay = 1000) {
    let begin = 0;
    return function() {
        let now = new Date().getTime();
        if (now - begin >= delay) {
            fn.apply(this, arguments);
        }
        begin = now;
    }
}


/**
 * 重载
 * 刷新函数, 只触发短时间内触发多次中的最新一次
 */
export let p = null;
export function tVariantSetTimeout(fn, time) {
    if (p !== null) clearTimeout(p);
    p = setTimeout(() => {
        fn();
    }, time)
}